package com.example.mynewsapp.adapter

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.example.mynewsapp.fragment.Fragment.TAB_VIDEO
import com.example.mynewsapp.fragment.Fragment.TAB_VIDEO_CN
import com.example.mynewsapp.fragment.video.*
import com.example.mynewsapp.util.Utils

class VideoSectionAdapter(private val context: Context, fm: FragmentManager)
    : FragmentPagerAdapter(fm) {

    //顶部tablayout的字符
//    private lateinit var TAB_TITLES :Array<String>

    override fun getItem(position: Int): Fragment {
        // 顶部有多少个tab，就会运行多少次（初次会加载第一第二，第三第四要点第三个tab才会运行）
        /*******新建Fragment******/
//        Log.d("WY+","运行第几次："+(position+1))
        when (position) {
            0 -> {
                return FragmentLife.newInstance(0)
            }
            1 -> {
                return FragmentCartoon.newInstance(0)
            }
            2 -> {
                return FragmentFun.newInstance(0)
            }
            3 -> {
                return FragmentFood.newInstance(0)
            }
            4 -> {
                return FragmentSport.newInstance(0)
            }
            5 -> {
                return FragmentMusic.newInstance(0)
            }
            6 -> {
                return FragmentPet.newInstance(0)
            }
            7 -> {
                return FragmentTechnology.newInstance(0)
            }
            8 -> {
                return FragmentGame.newInstance(0)
            }
            9 -> {
                return FragmentLife.newInstance(0)
            }
        }
        return FragmentLife.newInstance(0)

    }

    override fun getPageTitle(position: Int): CharSequence? {
        if (Utils.getCountry() == "cn") {
            return TAB_VIDEO_CN[position]
        }
        return TAB_VIDEO[position]
    }

    override fun getCount(): Int {
        // 顶部显示多少个页，不要超过TAB_TITLES的总数.
        return TAB_VIDEO.size
    }
}